﻿/* Project: Side Scrolling Shooter
 * An object that handles the creation of new enemies.
 * Last Update: 4/9/11,9:53PM
 */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Project1
{
    public class Army: GameComponent
    {
        public List<Enemy> Enemies;
        private float passedTime, countdown;
        private float interval; // needs to increase
        private int maxEnemies;
        private int RightEdge; // right edge of screen
        private int GroundHeight;
        private Random r;

        public Army(Game g)
            : base(g)
        {
            Enemies = MainGame.Enemies;
            r = new Random();
            passedTime = 0;
            interval = 2;
            RightEdge = MainGame.borderRightX;
            GroundHeight = MainGame.borderY - 20;
            countdown = 2 + r.Next(5);
        }

        public void newRandomEnemy()
        {
            int index = r.Next(10);
            if (index <= 6)
            {
                // New enemy 1 (airship)
                int y = 25 + r.Next(200);
                Enemies.Add(new Enemy1(Game,
                    new Vector2(RightEdge, y)));
            }
            else
            {
                // New enemy 2 (tank)
                Enemies.Add(new Enemy2(Game,
                    new Vector2(RightEdge, GroundHeight)));
            }

        }

        public override void Update(GameTime gameTime)
        {
            

            if (countdown > 0) countdown--;
            else
            {
                newRandomEnemy();
                Random r = new Random();
                countdown = (float)(10 + r.Next(18));
            }

            if (passedTime > interval && maxEnemies < 15)
            {
                maxEnemies++;
                // Increase maximum enemy limit
                passedTime = 0;
                interval *= 1.5f;
            }

            base.Update(gameTime);
        }
    }
}
